package com.sunfeng.chap2.p13;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2021/10/9  18:20
 */
public class Test13_21 {
    public static void main(String[] args) {
        try {
            RandomAccessFile randomAccessFile = new RandomAccessFile("D:\\nio\\a.txt", "rw");
            FileChannel channel = randomAccessFile.getChannel();
            System.out.println("开始获取锁");

            channel.lock(0, Long.MAX_VALUE, true);

            System.out.println("我拿到锁了");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
